/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 2

Description:
A simple linked list implementation. It has, in addition to a normal linked 
list, an item count, and pointers to both the anchor, and the last item.
oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#ifndef LINKED_LIST_H
#define LINKED_LIST_H

#include <windows.h> // For BOOL


struct TListItemStruct
{
	void* Value;
	struct TListItemStruct* NextItem;
	struct TListItemStruct* PrevItem;
};
typedef struct TListItemStruct TListItem;
typedef TListItem* PListItem;

struct TListStruct
{
	PListItem Anchor;
	PListItem Last;
	int Count;
	CRITICAL_SECTION ListProtector;
};
typedef struct TListStruct TList;
typedef TList* PList;


/* InitializeList()
 * -----------------------------------
 * Returns a newly allocated list														*/
PList InitializeList();

/* CreateValue(void* value)
 * -----------------------------------
 * Returns a new list item with value assigned to it									*/
PListItem CreateValue(void* value);

/* AddValue(PList list, void* value);
 * -----------------------------------
 * Creates a new list item, assigning value to it, and adds it 
 * to list (on the end of the list). Returns the added list item (if it was added)		*/
PListItem AddValue(PList list, void* value);

/* AddItem(PList list, PListItem item)
 * -----------------------------------
 * Adds item to list (on the end of the list) and returns the item (if it was added)	*/
PListItem AddItem(PList list, PListItem item);

/* RemoveItem(PList list, PListItem item);
 * -------------------------------------------------------------------------
 * Removes item from list, and frees item (and its value!)
 * Returns TRUE on success																*/
// REMOVED FOR SIMPLICITY
// BOOL RemoveItem(PList list, PListItem item);

/* GetNext(PListItem item)
 * -------------------------------------------------------------------------
 * Returns the next item in the list after item											*/
PListItem GetNext(PListItem item);

/* GetPrev(PListItem item)
 * -------------------------------------------------------------------------
 * Returns the previous item in the list before item									*/
PListItem GetPrev(PListItem item);

/* GetCount(PList list);
 * -------------------------------------------------------------------------
 * Safely (thread-wise) return the number of items in the list							*/
int GetCount(PList list);

/* FreeList(PList list);
 * -------------------------------------------------------------------------
 * Frees list, freeing all its items													*/
BOOL FreeList(PList list);



#endif // LINKED_LIST_H